<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib  prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<%@page import="com.webside.points.wechat.Wechat"%>
<%
	 //正常跳转
	String code = (String)request.getParameter("code");
  
	String openId = null;
	
	if(code != null){
		Wechat.getOpenId(code,request,response);
	}
	
	if(openId == null){
		openId = (String)request.getParameter("openId");
		
		openId = (String)request.getSession().getAttribute("openId");
		
		if(openId!=null){
			request.getSession().setAttribute("openId",openId);
		}
	}
	//如果从其他界面返回时，code已经失效，需要重新请求一次
	
	if(openId == null){
	   response.sendRedirect("../wechat/getWeChatCode");
	   return;
	}  
	
 %> 
<%-- <% 
 	String openId=(String)request.getSession().getAttribute("openId");
 %> --%>
<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"/>
  <meta name="keywords" content="" />
  <meta name="description" content="" />
  <link rel="stylesheet" href="../css/amazeui.min.css">
  <link rel="stylesheet" href="../css/wap.css">
  	<link rel="stylesheet" href="../css/style.css"/>
  	<link rel="stylesheet" href="../css/weui.css" />
	<script src="../js/jquery.js"></script>
	   <script type="text/javascript"
	src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
	<script type="text/javascript" src="../js/timeago.js"></script>
	<link rel="stylesheet" href="../css/dropload.css">
  	<script src="../js/jquery.min.js"></script>
	<script src="../js/dropload.min.js"></script>
	<script src="../js/jssdk.js"></script>
  	<script type="text/javascript">
	  	$(function(){
			//查询审核专家数量
			$.post("${ctx }/expert/findAuditExpert" ,{page:0,size:0}, 
			function(data, status, xhr){
				$("#expertCountId").text(data.length);
			},
			'json');
			//查询抢答数量
			$.post("${ctx }/issue/queryAnswer" ,{openId:'<%=openId %>',page:0,size:0} , 
				function(data, status, xhr){
					var count = 0;
					for(var i = 0;i<data.length;i++){
						if(data[i].userEntity.openId != '<%=openId %>'){
							count++;
						}
					}
					$("#answerCountId").text(count)
				},
			'json');
	  	})
		
		$(function(){
			// 页数
			var page = 0;
			// 每页展示多少个
			var size = 10;
			var openId = $("#openId").val();
			// dropload
			$('.content').dropload({
				scrollArea : window,
				loadDownFn : function(me){
					page++;
					// 拼接HTML
					var result = '';
					$.ajax({
						type: 'post',
						url: '../issue/findIssueRecord?page='+page+"&size="+size+"&openId="+openId,
						dataType: 'json',
						success: function(data){
							var arrLen = data.length;
							//alert(page);
							if(arrLen > 0){
								for(var i=0; i<arrLen; i++){
									//判断是否停用
									if(data[i].status==1){
										result +=   '<li class="am-g am-list-item-desced pet_list_one_block">'
											+' <a href="${ctx }/issue/findById?issueId='+data[i].id+'&openId=&mark=issue" class="issue">'
											+'<div class="pet_list_one_info">'
												+'<div class="pet_list_one_info_l">'
													+'<div class="pet_list_one_info_ico"><img src="${user.headUrl }" alt=""></div>'
													+'<div class="pet_list_one_info_name">${user.wechatId }</div>'
												+'</div>'
												+' <div class="pet_list_one_info_r">'
												+' <div class="pet_list_tag"><span class="timeago">'+timeago(data[i].createDateFormat)+'</span></div>'
												+'</div>'
											+'</div>'
											+'<div class=" am-list-main">'
												+'<h3 class="am-list-item-hd pet_list_one_bt" style="color: #222;font-weight: bold;">'+data[i].issueContent+'</h3>'
											+'</div>'
											+' <div style="color:#969595;font-size:1.1rem;margin-top:10px;" id="'+data[i].id+'" class="like">'
											+'<span id="like'+data[i].id+'"></span>'
											+'<span id="dislike'+data[i].id+'"></span>'
											+'</div>'
											+'</a>'
										+'</li>';
									}
								}
													
							// 如果没有数据
							}else{
								// 锁定
								me.lock();
								// 无数据
								me.noData();
							}
							// 插入数据到页面，放到最后面
							$('.am-list').append(result);
							// 每次数据插入，必须重置
							me.resetload();
							
							$("li .like").each(function(){
								var id=$(this).attr("id");
								 //alert(id);
								var span=$(this);
								var url="${ctx}/answer/findByIssueId";
								$.post(url, {"issueId":id}, function(data, status, xhr){
									callback(data);
								},'json');
								function callback(data){
									var like=0;
									var dislike=0;
									for(var i=0;i<data.length;i++){
										like+=data[i].likeMark;
										dislike+=data[i].dislikeMark;
									}
									//alert($("#like"+id).length);
									$("#like"+id).text(like+"人点赞 ");
									$("#dislike"+id).text(dislike+"人倒赞");	
								}	
							 });
						},
						error: function(xhr, type){
							//alert('Ajax error!');
							// 即使加载出错，也得重置
							me.resetload();
						}
					});
				}
			});
		});
  	</script>
  <title>个人信息</title>
</head>
<body style="background:#ececec">
<input type="hidden" value="<%=openId %>" id="openId">
  <div class="pet_mian" >
    <div class="pet_content pet_content_list">
      <div class="pet_grzx">
		<c:if test="${user.expertId!=0}">
	      <!--专家用户-->
          <div class="pet_grzx_nr">
              <div class="pet_grzx_ico">
                <img src="${user.headUrl }" >
              </div>
              <div class="pet_grzx_name">${user.wechatId }</div>
              <div class="pet_grzx_num_font">
              	<c:if test="${user.expertEntity.auditStatus==1}">
              		<c:forEach items="${issueTypeList }" var="issueType">
              			<c:if test="${issueType.id==user.expertEntity.expertType }">
              				${issueType.issueTypeName }专家<br />
              			</c:if>
              		</c:forEach>
                 </c:if>
				 <c:if test="${user.expertEntity.auditStatus==1}">
                 	 <a href="${ctx}/expert/findByExpertInfo?expertId=${user.expertId}" style="color:#22ac38;">修改资料</a><br />
                 </c:if>
                 <c:if test="${user.expertEntity.auditStatus==0}">
                 	<span style="color: #f39800;">正在审核</span> 
                 </c:if>
                 <c:if test="${user.expertEntity.auditStatus==2}">
                 	<span style="color: red;">已停用</span>
                 </c:if>
				  <c:if test="${user.expertEntity.auditStatus==3}">
                 	<a href="${ctx}/expert/findByExpertInfo?expertId=${user.expertId}" style="color:red;">审核未通过，修改资料</a>
                 </c:if>
              </div>
              <div class="pet_grzx_num">
                <span>${issueCount }<i>问题</i></span>
				<span>${user.expertEntity.likeCount }<i>喜欢</i></span>
				<span>${user.payment }<i>付款</i></span>
                <span>${answerCount }<i>回答</i></span>
                <span>${user.expertEntity.dislikeCount }<i>不喜欢</i></span>
                <span>${user.expertEntity.rewardAmount }<i>收入</i></span>
              </div>           
            <a class="weui-cell weui-cell_access" href="${ctx }/issue/findIssueRecordUI?openId=<%=openId %>">
                <span class="weui-cell__bd">
                    <span style="vertical-align: middle">我的提问</span>
                </span>
                <span class="weui-cell__ft"></span>
            </a>
			<a class="weui-cell weui-cell_access" href="${ctx }/answer/findAnswerRecordUI?openId=<%=openId %>">
                <span class="weui-cell__bd">
                    <span style="vertical-align: middle">我的回答</span>
                </span>
                <span class="weui-cell__ft"></span>
            </a>
			<c:if test="${user.manageStatus==1}">
			<!--<a class="weui-cell weui-cell_access" href="${ctx }/service/post-form.jsp">
                <span class="weui-cell__bd">
                    <span style="vertical-align: middle">编写文章</span>
                </span>
                <span class="weui-cell__ft"></span>
            </a>-->
			</c:if>
            <a class="weui-cell weui-cell_access" href="${ctx }/issue/queryAnswerUI?openId=<%=openId %>">
                <span class="weui-cell__bd">
                    <span style="vertical-align: middle">有<font id="answerCountId">0</font>个问题等待回答</span>
                </span>
                <span class="weui-cell__ft"></span>
            </a>
			<c:if test="${user.manageStatus==1}">
				<a class="weui-cell weui-cell_access" href="${ctx }/service/audit-expert.jsp">
					<span class="weui-cell__bd">
						<span style="vertical-align: middle">有<font id="expertCountId">0</font>个专家等待审核</span>
					</span>
					<span class="weui-cell__ft"></span>
				</a>
			</c:if>
          </div>
		  <div class="pet_grzx_list"></div>
		  </c:if>
		  <c:if test="${user.expertId==0}">
		  <!--普通用户-->
		   <div class="pet_grzx_nr">
              <div class="pet_grzx_ico">
                <img src="${user.headUrl }" >
              </div>
              <div class="pet_grzx_name">${user.wechatId }</div>
              <div class="pet_grzx_num_font">
				<a href="${ctx }/expertProtocol/findExpertProtocol" style="color:#22ac38;">申请成为专家</a>
              </div>
              <div class="pet_grzx_num">
                <span>${issueCount }<i>提问</i></span>
				<span>${user.studyNumber }<i>学习</i></span>
				<span>${user.payment }<i>打赏</i></span>
              </div>
          </div>
		<div class="pet_mian" style="border-top:10px solid #f1f1f1;">
			<div class="pet_content pet_content_list">
			  <div class="pet_article_like">
				<div class="pet_content_main pet_article_like_delete">
				  <div data-am-widget="list_news" class="am-list-news am-list-news-default am-no-layout" >
					<div class="am-list-news-bd content">
					  <ul class="am-list">

					  </ul>
					  </div>
					</div>
				  </div>
				</div>
			  </div>
			</div>
			</c:if>
        </div>

      </div>
 <!--底部-->
    <div data-am-widget="navbar" class="am-navbar am-cf my-nav-footer " id="">
     <ul class="am-navbar-nav am-cf am-avg-sm-4 my-footer-ul">
		<li>
           <a href="${ctx }/user/findUserIssue?issueTypeId=0" class="">
            <span class="am-icon-home"></span>
            <span class="am-navbar-label">首页</span>
          </a>
        </li>
        <li>
          <a href="${ctx }/issueType/findAll?mark=service&openId=<%=openId %>" class="">
            <span class="am-icon-comments"></span>
            <span class="am-navbar-label">提问</span>
          </a>
        </li>
		<li>
          <a href="${ctx }/postType/findAllPostType" class="">
            <span class="am-icon-book"></span>
            <span class="am-navbar-label">学习</span>
          </a>
        </li>
        <li style="position:relative">
          <a href="${ctx }/user/findByOpenId?openId=<%=openId %>" class="">
            <span class="am-icon-user"></span>
            <span class="am-navbar-label">我的</span>
          </a>
        </li>
      </ul>
</div>
    </div>
  <script src="../js/amazeui.min.js"></script>
    <script src="../js/text-calculation.js"></script>
</body>
  </html>